package com.sk.restree.model.action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

import com.sk.restree.model.dao.StatusDAO;
import com.sk.restree.model.dto.StatusDTO;

public class UsedBenefitList implements Action {

	@Override
	public Object execute(HttpServletRequest request,
			HttpServletResponse response) {
		String member_id = request.getParameter("member_id");
		StatusDAO dao = StatusDAO.getInstance();
		List<StatusDTO> list = dao.getUsedBenefitList(member_id);
		ObjectMapper om = new ObjectMapper();
		List<Map<String,String>> returnList = new ArrayList<Map<String,String>>();
		for(StatusDTO dto:list){
			Map<String,String> map = new HashMap<String, String>();
			map.put("member_id", dto.getMember_id());
			map.put("fee", dto.getFee());
			map.put("date", dto.getJoindate());
			map.put("name", dto.getName());
			map.put("store_id", dto.getStore_id());
			returnList.add(map);
		}
		if(list!=null)
			try {
				om.writeValue(response.getWriter(), returnList);
			} catch (JsonGenerationException e) {
				e.printStackTrace();
			} catch (JsonMappingException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		return null;
	}

}
